Public Class DataGridViewLookUpComboBoxEditControl

    Private _DGV As DataGridView
    Private _ValueIsChanged As Boolean = False
    Private _RowIndex As Integer

    Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle) Implements System.Windows.Forms.IDataGridViewEditingControl.ApplyCellStyleToEditingControl
        Me.Font = dataGridViewCellStyle.Font
        Me.ForeColor = dataGridViewCellStyle.ForeColor
        Me.BackColor = dataGridViewCellStyle.BackColor
        If Me.DropDownStyle <> ComboBoxStyle.DropDownList Then
            Me.AutoCompleteMode = Windows.Forms.AutoCompleteMode.SuggestAppend
            Me.AutoCompleteSource = Windows.Forms.AutoCompleteSource.ListItems
        End If
    End Sub

    Public Property EditingControlDataGridView() As System.Windows.Forms.DataGridView Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlDataGridView
        Get
            Return _DGV
        End Get
        Set(ByVal value As System.Windows.Forms.DataGridView)
            _DGV = value
        End Set
    End Property

    Public Property EditingControlFormattedValue() As Object Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlFormattedValue
        Get
            Return Me.Text
        End Get
        Set(ByVal value As Object)
            If TypeOf value Is String Then
                Me.Text = CStr(value)
            End If
        End Set
    End Property

    Public Property EditingControlRowIndex() As Integer Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlRowIndex
        Get
            Return _RowIndex
        End Get
        Set(ByVal value As Integer)
            _RowIndex = value
        End Set
    End Property

    Public Property EditingControlValueChanged() As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlValueChanged
        Get
            Return _ValueIsChanged
        End Get
        Set(ByVal value As Boolean)
            _ValueIsChanged = value
        End Set
    End Property

    Public Function EditingControlWantsInputKey(ByVal keyData As System.Windows.Forms.Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.EditingControlWantsInputKey

        Select Case keyData And Keys.KeyCode
            Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _
                Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp, _
                Keys.Shift, Keys.Delete, Keys.Back, Keys.CapsLock, _
                Keys.Insert, Keys.Control, Keys.Enter

                Return True

            Case Else
                Return Not dataGridViewWantsInputKey
        End Select
    End Function

    Public ReadOnly Property EditingPanelCursor() As System.Windows.Forms.Cursor Implements System.Windows.Forms.IDataGridViewEditingControl.EditingPanelCursor
        Get
            Return Me.Cursor
        End Get
    End Property

    Public Function GetEditingControlFormattedValue(ByVal context As System.Windows.Forms.DataGridViewDataErrorContexts) As Object Implements System.Windows.Forms.IDataGridViewEditingControl.GetEditingControlFormattedValue
        'Return Me.SelectedValue
        If Me.Text.Trim.Length > 0 AndAlso Me.FindString(Me.Text) >= 0 Then
            Return Me.Items.Item(Me.FindString(Me.Text)).ToString
        Else
            Return ""
        End If
    End Function

    Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) Implements System.Windows.Forms.IDataGridViewEditingControl.PrepareEditingControlForEdit
        If selectAll Then Me.SelectAll()
    End Sub

    Public ReadOnly Property RepositionEditingControlOnValueChange() As Boolean Implements System.Windows.Forms.IDataGridViewEditingControl.RepositionEditingControlOnValueChange
        Get
            Return False
        End Get
    End Property

    Protected Overrides Sub OnSelectedValueChanged(ByVal e As System.EventArgs)
        _ValueIsChanged = True
        _DGV.NotifyCurrentCellDirty(True)
        MyBase.OnSelectedValueChanged(e)
    End Sub

    Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
        _ValueIsChanged = True
        _DGV.NotifyCurrentCellDirty(True)
        MyBase.OnTextChanged(e)
    End Sub

End Class
